import os
import datetime
import signal


class TaskProcess:

    @classmethod
    async def init_process(cls, loop):
        cls.stopped = False
        cls.loop = loop

        def stop(sig, frame):
            cls.stopped = True
            print(f"修改stopped")
            try:
                from common.g.g import G_LOGGER
            except ImportError:
                G_LOGGER = None
            dt = datetime.datetime.now()
            if G_LOGGER:
                G_LOGGER.info(f"当前时间:{dt},任务:{cls.__class__.__name__},进程pid={os.getpid()},收到信号:{sig}~")

        signal.signal(signal.SIGPIPE, signal.SIG_IGN)
        signal.signal(signal.SIGINT, stop)
        signal.signal(signal.SIGQUIT, stop)
        signal.signal(signal.SIGTERM, stop)
        signal.signal(signal.SIGHUP, signal.SIG_IGN)

    @classmethod
    async def release_process(cls):
        pass

    async def run(self, worker_id):
        ...




